<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.google.appengine.api.users.User"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@ page import="javax.jdo.PersistenceManager"%>
<%@ page import="javax.jdo.Query"%>
<%@ page import="java.util.*"%>
<%@ page import="shared.*"%>
<%@ page import="pk1.*"%>
<%@ page import="member.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>點數交換網</title>

<style type="text/css"> 
/* remove link underline */
a {text-decoration: none 
} 
</style> 

<style>

    /* START - toptop menu */

ul#TTPM

{

    list-style: none;

    float: left;

    margin:0px;

    padding:0px;

}



ul#TTPM li ul {

    display: none;

}

ul#TTPM li

{

    list-style: none;

    font-weight:bold;

}

ul#TTPM li:hover > ul {

    display: block;

    position:absolute;

    z-index:500;

    padding:0px;

} 

/* END - toptop menu */

    </style>

<style type="text/css">
.title {
	font-size: 70px;
	font-weight: bolder;
	color: #000;
}
.new {
	color: #F06;
}
.tabletits {
	font-size: 36px;
	color: #FFFFFF;
	border-top-color: #000;
	border-right-color: #000;
	border-bottom-color: #000;
	border-left-color: #000;
	text-decoration: none;
	text-align: center;
}
a {text-decoration: none;
	 color: #000;
} 
.tabletit {
	font-size: 36px;
	color: #000;
	border-top-color: #000;
	border-right-color: #000;
	border-bottom-color: #000;
	border-left-color: #000;
	text-decoration: none;
	text-align: center;
}
body {
	background-color: #99C;
}
.tblCon {
	font-size: 16px;
	font-weight: bold;
	color: #000;
	text-decoration: none;
	text-align: center;
}


.tablein {
	font-size: 36px;
	color: #CCC;
	background-color: #000;
}

.tableins {
	font-size: 36px;
	color: #CCC;
	background-color: #000;
	color: #CC3333;
}


</style>



</head>




<body>


<table width="1038" height="512" border="0" align="center">
<tr>
  <th height="188" colspan="4" rowspan="2" class="title" scope="col">會員管理</th>
  <th width="371" height="299" scope="col" align="left">
  <%
	UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    String userName = "";
    boolean intiLogin = true;
    if (user != null) {
	    	userName = user.getNickname();
	    %>
	    <p>您目前是以 <u><%= userName %></u>登入<br>
	        如果這不是您的帳號</p>
	    <p>您可以<u><a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">登出</a></u>，再重新登入！</p>
		<p><u><a href="/mem/editMem01.jsp"><span class="tabletx">修改會員資料</span></a></u></p>
		<%
		//if是管理員印出管理頁面的圖示
	    PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(Member.class);
		query.setFilter("transTimes >= 0");
		try {
		    List<Member> results = (List<Member>) query.execute(userName);
		    if (!results.isEmpty()) {
		    	for (Member p : results) {
		    		if(userName.equals(p.getName())){
		    			if(p.getRequirement() == true){
			    			%>
			    		    <div id="apDiv1"><a href="admminpg.jsp"><img src="../adminIcon.png" width="87" height="105" /></a></div></th>
			    		    <%
			    		    break;
			    		}
					}
		    	}
		    } else {
		    	out.println("無會員資料!");
		    }
		} finally {
		    query.closeAll();
		    pm.close();
		}		
	
    } else {
    	%>
    		<p>請
    		<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">登入</a>,
    		以便開始點數交換</p>
    	<%
        }
	
    
    
	    
    
    //END
    %>
  <td width="1"></th>
</tr>
<tr>
   <td height="44"><p><a href="index_un.jsp" class="accept">回首頁</a></p></td>
</tr>
<tr>
  <th width="153" height="133" bgcolor="#0066FF" class="tabletit" scope="row">
    <ul id="TTPM">

        <li id="TTPMI">我的活動

            <ul>

                <li><a href="StrtPg.jsp" ><span class="tablein">發起</span></a></li>

                <li><a href="Attend.jsp" ><span class="tablein">參與</span></a></li>


            </ul>

        </li>

    </ul></th>
  <th width="167" bgcolor="#CC66CC" scope="row"><a href="../record.jsp" class="tabletits" >交易紀錄</a></th>
 <th width="161" bgcolor="#FFFF33" scope="row"><a href="../MyInv.jsp" class="tabletit">我的邀請</a></th>
  <th width="159" bgcolor="#CC3333" scope="row"><a href="../mesg.jsp" class="tabletit">留言</a></th>
  <td>&nbsp;</td>
</tr>
 <tr>
    <th height="21" colspan="8" bgcolor="#000000" scope="row">&nbsp;</th>
  </tr>
<%
		
		PersistenceManager pm2 = PMF.get().getPersistenceManager();
		Query query2 = pm2.newQuery(Record.class);
		try {
				List<Record> results = (List<Record>) query2.execute();
			
	%>
</table>
 <table>
<form method="get" action="/ConfirmServlet" >
<div id="content">
<div class="content_item">
<tr>
			<td>受邀者</td>
			<td>邀請者</td>
			<td>活動名稱</td>
			<td>受邀者交換條件</td>
			<td>邀請者交換條件</td>
			<td>日期</td>
			<td width="42">留言</td>
			<td width="42">交易狀態</td>
            <td>評分</td>
		</tr>
		<%
		
			for (Record rec : results) {
				if (rec.checkRecord(userName)){
		%>
		<tr>
			<td><input type = "hidden" name = "inviterd_ID" value="<%=rec.getInviterdID()%>"/><%=rec.getInviterdID()%></td>
			<td><input type = "hidden" name = "inviter_ID" value="<%=rec.getInviterID()%>" /><%=rec.getInviterID()%></td>
			<td><input type = "hidden" name = "invite_activity" value="<%=rec.getInviteActivity()%>" /><%=rec.getInviteActivity()%></td>
			<td><input type = "hidden" name = "inviterd_con" value="<%=rec.getInviterdCon()%>" /><%=rec.getInviterdCon()%></td>
			<td><input type = "hidden" name = "inviter_con" value="<%=rec.getInviterCon()%>" /><%=rec.getInviterCon()%></td>
			<td><input type = "hidden" name = "invite_date" value="<%=rec.getInviteDate()%>" /><%=rec.getInviteDate()%></td>
			<td><input type = "hidden" name ="invite_message" value="<%=rec.getInviteMessage()%>" /><%=rec.getInviteMessage()%></td>
			<td><input type = "hidden" name ="status" value="<%=rec.getStatus()%>" />
			<%
				if(String.valueOf(rec.getStatus()).equals("UnConfirm"))
				{
					
					%>
			<label>
                <input type="submit" name="check1"  value="成功" />
                <input type="submit" name="check2"  value="失敗" />
              </label>
             <% 
				}else{
					out.print(rec.getStatus());
					
				}
             %> 
			</td>
            
		</div></div>
		</form>
            <td>
			<form name="form2" action="SScore.jsp" method="get">
			<input type="submit" value="評分" />
			</form>
			</td>
		</tr>
		<%
			}//if
				}// for
					
				} finally {
					query2.closeAll();
					pm2.close();
				}
%>

</table>

</body>
</html>